package com.ruoyi.iot.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.iot.domain.IotProductAttributeModel;
import com.ruoyi.iot.service.IIotProductAttributeModelService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 产品属性模型Controller
 *
 * @author ruoyi
 * @date 2025-02-26
 */
@RestController
@RequestMapping("/iot/attribute")
public class IotProductAttributeModelController extends BaseController {
    @Autowired
    private IIotProductAttributeModelService iotProductAttributeModelService;

    /**
     * 查询产品属性模型列表
     */
    @GetMapping("/list")
    public TableDataInfo list(IotProductAttributeModel iotProductAttributeModel) {
        startPage();
        List<IotProductAttributeModel> list = iotProductAttributeModelService.selectIotProductAttributeModelList(iotProductAttributeModel);
        return getDataTable(list);
    }

    /**
     * 导出产品属性模型列表
     */
    @Log(title = "产品属性模型", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, IotProductAttributeModel iotProductAttributeModel) {
        List<IotProductAttributeModel> list = iotProductAttributeModelService.selectIotProductAttributeModelList(iotProductAttributeModel);
        ExcelUtil<IotProductAttributeModel> util = new ExcelUtil<IotProductAttributeModel>(IotProductAttributeModel.class);
        util.exportExcel(response, list, "产品属性模型数据");
    }

    /**
     * 获取产品属性模型详细信息
     */
    @GetMapping(value = "/{attributeId}")
    public AjaxResult getInfo(@PathVariable("attributeId") Long attributeId) {
        return success(iotProductAttributeModelService.selectIotProductAttributeModelByAttributeId(attributeId));
    }

    /**
     * 新增产品属性模型
     */
    @Log(title = "产品属性模型", businessType = BusinessType.INSERT)
    @PostMapping(value = "/add")
    public AjaxResult add(@RequestBody IotProductAttributeModel iotProductAttributeModel) {
        iotProductAttributeModel.setCreateBy(getUsername());
        return toAjax(iotProductAttributeModelService.insertIotProductAttributeModel(iotProductAttributeModel));
    }

    /**
     * 修改产品属性模型
     */
    @Log(title = "产品属性模型", businessType = BusinessType.UPDATE)
    @PutMapping(value = "/edit")
    public AjaxResult edit(@RequestBody IotProductAttributeModel iotProductAttributeModel) {
        iotProductAttributeModel.setUpdateBy(getUsername());
        return toAjax(iotProductAttributeModelService.updateIotProductAttributeModel(iotProductAttributeModel));
    }

    /**
     * 删除产品属性模型
     */
    @Log(title = "产品属性模型", businessType = BusinessType.DELETE)
    @DeleteMapping("/{attributeIds}")
    public AjaxResult remove(@PathVariable Long[] attributeIds) {
        return toAjax(iotProductAttributeModelService.deleteIotProductAttributeModelByAttributeIds(attributeIds));
    }
}
